//
//  MYGMinContentCell.swift
//  MYDoctor
//
//  Created by 小火科技 on 2024/4/10.
//

import UIKit

class MYGMinContentCell: UITableViewCell {
    
    var model: MYGMicrosrationDyModel? {
        didSet {
            
            guard let item = model else  {
                return
            }
            
            let time = item.updated_at
            var M :Int = 1
            var D :Int = 1
            if let date = time.date(withFormat: "yyyy-MM-dd HH:mm:ss") {
                let calendar = Calendar.current
                let components = calendar.dateComponents([.month], from: date)
                let componentsDay = calendar.dateComponents([.day], from: date)
                if let month = components.month {
                    print("月份是：\(month)")
                    M = month
                }
                if let day = componentsDay.day {
                    print("月份是：\(day)")
                    D = day
                }
            } else {
                print("日期字符串格式不正确")
            }
        
            
            timeLabel.rz.colorfulConfer { confer in
                confer.text("\(D)")?.font(.medium(18)).textColor(.rgba(54, 53, 56, 1))
                confer.text("\(M)月")?.font(.regular(10)).textColor(.rgba(54, 53, 56, 1))
            }
            if item.medias.count > 0 {
                let name = item.medias.first!
                bkImageView.sd_setImage(with: URL(string: "\(name)"), placeholderImage: UIImage(named: "Chat/Function/image"))
            }
            
            tipLab.text = item.content
            workLab.text = item.address
            timeSubLab.text = item.created_at
            
        }
        
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        initUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initUI(){
        contentView.backgroundColor = .rgba(255, 255, 255, 1)
        
        contentView.addSubview(timeLabel)
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(22.5)
            make.top.equalTo(14.5)
            make.height.equalTo(25)
        }
        contentView.addSubview(tipLab)
        contentView.addSubview(workLab)
        contentView.addSubview(timeSubLab)
        contentView.addSubview(bkImageView)
       
        bkImageView.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-17.5)
            make.width.equalTo(97)
            make.height.equalTo(70)
            make.centerY.equalToSuperview()
        }
        
        tipLab.snp.makeConstraints { make in
            make.left.equalTo(75.5)
            make.top.equalTo(timeLabel)
            //make.height.equalTo(39)
            make.right.equalTo(bkImageView.snp.left).offset(-20)
        }
        workLab.snp.makeConstraints { make in
            make.left.equalTo(tipLab)
            make.top.equalTo(tipLab.snp.bottom).offset(5)
            make.height.equalTo(12.5)
        }
        
        timeSubLab.snp.makeConstraints { make in
            make.bottom.equalTo(bkImageView)
            make.left.equalTo(tipLab)
            
        }
        
    }
    private lazy var timeLabel: UILabel = {
        let label = UILabel()
        label.rz.colorfulConfer { confer in
            confer.text("22")?.font(.medium(18)).textColor(.rgba(54, 53, 56, 1))
            confer.text("8月")?.font(.regular(10)).textColor(.rgba(54, 53, 56, 1))
        }
        return label
    }()
    
    
    private lazy var tipLab:UILabel = {
        let tw = UILabel()
        tw.text = "中南大学湘雅医院成功完帕 金森病基因治疗"
        tw.textColor = .rgba(51, 51, 51, 1)
        tw.font = .medium(13)
        tw.lineBreakMode = .byTruncatingTail
        tw.numberOfLines = 2
        return tw
    }()
    
    private lazy var workLab:UILabel = {
        let tw = UILabel()
        tw.text = "媒体单位媒体单位"
        tw.textColor = .rgba(255, 59, 48, 1)
        tw.font = .regular(9)
        return tw
    }()
    
    private lazy var timeSubLab:UILabel = {
        let tw = UILabel()
        tw.text = "2023-09-09"
        tw.textColor = .rgba(128, 128, 128, 1)
        tw.font = .regular(8)
        return tw
    }()
    
    private lazy var bkImageView:UIImageView = {
        let bkView = UIImageView()
        bkView.layer.cornerRadius = 4
        bkView.layer.masksToBounds = true
        bkView.image = UIImage(named: "Chat/Function/image")
        return bkView
    }()
    
}
